package com.avic.rong.goodsSort.adapter.drawerAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.bean.secondDrawerBean.GoodsSortGjDrawerOtherBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/15 20:22
 * E-Mail Address：16601203965@163.com
 * 使用方式
 */
public class GoodsSortGjDrawerUsageModeAdapter extends RecyclerView.Adapter<GoodsSortGjDrawerUsageModeAdapter.GoodsSortWdDrawerOtherViewHolder> {
    private Context context;
    private LayoutInflater inflater;
    private View view;
    //使用方式
    private List<GoodsSortGjDrawerOtherBean> usageModeList = new ArrayList<>();

    private GoodsSortGjDrawerUsageModeListener goodsSortGjDrawerUsageModeListener;

    public GoodsSortGjDrawerUsageModeListener getGoodsSortGjDrawerUsageModeListener() {
        return goodsSortGjDrawerUsageModeListener;
    }

    public void setGoodsSortGjDrawerUsageModeListener(GoodsSortGjDrawerUsageModeListener goodsSortGjDrawerUsageModeListener) {
        this.goodsSortGjDrawerUsageModeListener = goodsSortGjDrawerUsageModeListener;
    }

    public GoodsSortGjDrawerUsageModeAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setUsageModeList(List<GoodsSortGjDrawerOtherBean> usageModeList) {
        this.usageModeList = usageModeList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GoodsSortWdDrawerOtherViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        view = inflater.inflate(R.layout.view_goods_rv_item1, viewGroup, false);
        return new GoodsSortWdDrawerOtherViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsSortWdDrawerOtherViewHolder holder, int i) {
        holder.tv.setText(usageModeList.get(i).getAttrValue());
        holder.tv.setSelected(usageModeList.get(i).isSelected());
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goodsSortGjDrawerUsageModeListener.setUsageModeListSelected(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return usageModeList.size();
    }

    class GoodsSortWdDrawerOtherViewHolder extends RecyclerView.ViewHolder {
        TextView tv;

        public GoodsSortWdDrawerOtherViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Item_tv1);
        }
    }

    public interface GoodsSortGjDrawerUsageModeListener {
        void setUsageModeListSelected(int index);
    }
}
